package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackStat;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TrackStatMapper extends BaseMapper<TrackStat> {

    @Select("select track_id,\n" +
            "       max(if(stat_type = '0701', stat_num, 0)) as playStatNum,\n" +
            "       max(if(stat_type = '0702', stat_num, 0)) as collectStatNum,\n" +
            "       max(if(stat_type = '0703', stat_num, 0)) as praiseStatNum,\n" +
            "       max(if(stat_type = '0704', stat_num, 0)) as commentStatNum\n" +
            "from track_stat\n" +
            "where track_id = #{trackId}\n" +
            "  and is_deleted = 0;")
    TrackStatVo selectTrackStat(Long trackId);
}
